var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
var stdin_exports = {};
__export(stdin_exports, {
  default: () => stdin_default
});
module.exports = __toCommonJS(stdin_exports);
var import_swiper_uniapp_sfc = require("./swiper.uniapp-sfc.css");
var import_vue = require("vue");
var import_aspect_ratio = __toESM(require("../aspect-ratio/aspect-ratio.js"));
var import_contact_button = __toESM(require("../contact-button/contact-button.js"));
var import_image = __toESM(require("../image/image.js"));
var import_utils = require("../utils");
var import_helper = require("./helper");
var import_vue2 = require("vue");
const __vue_sfc__ = (0, import_vue.defineComponent)({
  name: (0, import_utils.createNamespace)("Swiper")[0],
  options: {
    // https://uniapp.dcloud.io/matter.html#mp
    virtualHost: true
  },
  components: {
    FanAspectRatio: import_aspect_ratio.default,
    FanContactButton: import_contact_button.default,
    FanImage: import_image.default
  },
  props: import_helper.swiperProps,
  emits: import_helper.swiperEmits,
  setup(props, context) {
    const uniqueId = (0, import_utils.createUniqueId)({ prefix: "fanSwiper" });
    const innerCurrent = (0, import_vue.ref)(props.current);
    (0, import_vue.watch)(
      () => props.current,
      (val) => {
        if (val !== innerCurrent.value)
          innerCurrent.value = val;
      }
    );
    (0, import_vue.watch)(innerCurrent, (val, prevVal) => {
      if (val === prevVal)
        return;
      context.emit("update:current", val);
      context.emit("change", val);
      if (props.autoHeight) {
        if (itemRects[val])
          currentHeight.value = itemRects[val].height;
        updateAutoHeight();
      }
    });
    const { swiperWidth, swiperAspectRatio } = (0, import_helper.useSwiperState)(props);
    const _this = (0, import_vue.getCurrentInstance)();
    const getSwiperWidth = () => __async(this, null, function* () {
      const { type } = props;
      if (type !== 2)
        return;
      const rect = yield (0, import_utils.getElementBounding)({
        selector: "#" + uniqueId,
        scope: _this
      });
      if (!rect || !rect.watch)
        return;
      swiperWidth.value = rect.width;
    });
    (0, import_vue.onMounted)(getSwiperWidth);
    (0, import_vue.watch)(() => props.customStyle, getSwiperWidth);
    let autoHeightTimer;
    let itemRects = [];
    const currentHeight = (0, import_vue.ref)(0);
    const theStyle = (0, import_vue.computed)(() => {
      const s = (0, import_utils.transformStyleSize)(props.customStyle);
      if (!props.autoHeight)
        return s;
      return `${s}height:${currentHeight.value}px;`;
    });
    const updateAutoHeight = () => {
      if (autoHeightTimer)
        clearTimeout(autoHeightTimer);
      const i = innerCurrent.value;
      setTimeout(() => __async(this, null, function* () {
        var _a;
        const rect = yield (0, import_utils.getElementBounding)({
          selector: ".fan-swiper__item--active",
          scope: _this
        });
        if ((rect == null ? void 0 : rect.height) !== ((_a = itemRects[i]) == null ? void 0 : _a.height)) {
          if (rect.height)
            itemRects[i] = rect;
          autoHeightTimer = setTimeout(updateAutoHeight, 150);
        } else {
          currentHeight.value = rect == null ? void 0 : rect.height;
        }
      }), 0);
    };
    (0, import_vue.onMounted)(() => {
      if (props.autoHeight)
        updateAutoHeight();
    });
    const onClick = (e, i) => {
      context.emit("click", e, i);
    };
    const showSlot = (0, import_vue.computed)(() => {
      return props.customItem || context.slots.default;
    });
    const onChange = (e) => {
      var _a;
      const source = (_a = e.detail) == null ? void 0 : _a.source;
      if (source == "autoplay" || source == "touch") {
        innerCurrent.value = e.detail.current;
      }
    };
    return {
      uniqueId,
      theStyle,
      innerCurrent,
      swiperAspectRatio,
      showSlot,
      onClick,
      onChange
    };
  }
});
function __vue_render__(_ctx, _cache) {
  const _component_FanImage = (0, import_vue2.resolveComponent)("FanImage");
  const _component_FanContactButton = (0, import_vue2.resolveComponent)("FanContactButton");
  const _component_swiper_item = (0, import_vue2.resolveComponent)("swiper-item");
  const _component_swiper = (0, import_vue2.resolveComponent)("swiper");
  const _component_FanAspectRatio = (0, import_vue2.resolveComponent)("FanAspectRatio");
  return _ctx.list && _ctx.list.length ? ((0, import_vue2.openBlock)(), (0, import_vue2.createBlock)(_component_FanAspectRatio, {
    key: 0,
    style: (0, import_vue2.normalizeStyle)(_ctx.theStyle),
    "aspect-ratio": _ctx.swiperAspectRatio
  }, {
    default: (0, import_vue2.withCtx)(() => [
      (0, import_vue2.createVNode)(_component_swiper, {
        id: _ctx.uniqueId,
        style: { "height": "100%", "max-height": "100%" },
        "adjust-height": "none",
        "indicator-dots": _ctx.list.length > 1 && _ctx.indicator,
        "indicator-color": "#f6f6f6",
        "indicator-active-color": _ctx.indicatorActiveColor,
        autoplay: !!_ctx.autoplay,
        interval: _ctx.autoplay,
        circular: _ctx.loop,
        duration: _ctx.duration,
        current: _ctx.innerCurrent,
        vertical: _ctx.vertical,
        "previous-margin": _ctx.type === 2 ? "38px" : "0",
        "next-margin": _ctx.type === 2 ? "38px" : "0",
        onChange: _ctx.onChange
      }, {
        default: (0, import_vue2.withCtx)(() => [
          ((0, import_vue2.openBlock)(true), (0, import_vue2.createElementBlock)(
            import_vue2.Fragment,
            null,
            (0, import_vue2.renderList)(_ctx.list, (item, index) => {
              return (0, import_vue2.openBlock)(), (0, import_vue2.createBlock)(
                _component_swiper_item,
                { key: index },
                {
                  default: (0, import_vue2.withCtx)(() => [
                    (0, import_vue2.createElementVNode)(
                      "view",
                      {
                        style: (0, import_vue2.normalizeStyle)({ height: _ctx.autoHeight ? "auto" : "100%" }),
                        class: (0, import_vue2.normalizeClass)(["fan-swiper__item", {
                          "fan-swiper__item--type2": _ctx.type === 2,
                          "fan-swiper__item--active": _ctx.innerCurrent === index
                        }])
                      },
                      [
                        _ctx.showSlot ? (0, import_vue2.renderSlot)(_ctx.$slots, "default", {
                          key: 0,
                          item,
                          index,
                          active: index === _ctx.innerCurrent
                        }) : ((0, import_vue2.openBlock)(), (0, import_vue2.createBlock)(_component_FanImage, {
                          key: 1,
                          "show-menu-by-longpress": _ctx.showMenuByLongpress,
                          src: item.cover,
                          mode: _ctx.autoHeight ? "widthFix" : "aspectFill",
                          "aspect-ratio": _ctx.autoHeight ? 0 : _ctx.aspectRatio,
                          radius: _ctx.innerRadius,
                          onClick: ($event) => _ctx.onClick(item, index)
                        }, null, 8, ["show-menu-by-longpress", "src", "mode", "aspect-ratio", "radius", "onClick"])),
                        item.link && item.link.mpContact ? ((0, import_vue2.openBlock)(), (0, import_vue2.createBlock)(_component_FanContactButton, {
                          key: 2,
                          full: true,
                          "mp-contact": item.link.mpContact
                        }, null, 8, ["mp-contact"])) : (0, import_vue2.createCommentVNode)("v-if", true)
                      ],
                      6
                      /* CLASS, STYLE */
                    )
                  ]),
                  _: 2
                  /* DYNAMIC */
                },
                1024
                /* DYNAMIC_SLOTS */
              );
            }),
            128
            /* KEYED_FRAGMENT */
          ))
        ]),
        _: 3
        /* FORWARDED */
      }, 8, ["id", "indicator-dots", "indicator-active-color", "autoplay", "interval", "circular", "duration", "current", "vertical", "previous-margin", "next-margin", "onChange"])
    ]),
    _: 3
    /* FORWARDED */
  }, 8, ["style", "aspect-ratio"])) : (0, import_vue2.createCommentVNode)("v-if", true);
}
__vue_sfc__.render = __vue_render__;
var stdin_default = __vue_sfc__;
